package com.assets.Check.offlineCheck;

import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;

import com.assets.Check.newTanWanCheck.BaseActivity1;
import com.assets.Check.newTanWanCheck.ItemCheckData;
import com.assets.databinding.ActivityOfficeCheckBinding;
import com.assets.newNHF.util.LogUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OfflineCheckActivity extends BaseActivity1 {
    private ActivityOfficeCheckBinding mBinding;
    private ArrayList<ItemCheckData> mDataList = new ArrayList<>();
    private OfflineCheckAdapter mAdapter = new OfflineCheckAdapter(mDataList);
    private Map<String, List<OfflineCheckData.AssetsBean>> map = new HashMap<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = ActivityOfficeCheckBinding.inflate(getLayoutInflater());
        setContentView(mBinding.getRoot());
        initView();
        initIntent();
    }

    private void initView() {
        mBinding.includeTitle.fh.setOnClickListener(v -> finish());
        mBinding.includeTitle.titleText.setText("离线盘点");
        mBinding.rcView.setLayoutManager(new LinearLayoutManager(this));
        mBinding.rcView.setAdapter(mAdapter);
    }

    private void initIntent() {
        OfflineCheckData offlineCheckData = getIntent().getParcelableExtra("offlineCheckData");
        for (OfflineCheckData.AssetsBean bean : offlineCheckData.getAssets1()) {//待盘点
            bean.setCheckStatus("待盘点");
            handleAssetsBeans(bean);
        }
        for (OfflineCheckData.AssetsBean bean : offlineCheckData.getAssets2()) {//已盘点
            handleAssetsBeans(bean);
            bean.setCheckStatus("已盘点");
        }
        for (OfflineCheckData.AssetsBean bean : offlineCheckData.getAssets3()) {//盘盈
            handleAssetsBeans(bean);
            bean.setCheckStatus("盘盈");
        }
        for (OfflineCheckData.AssetsBean bean : offlineCheckData.getAssets3()) {//盘亏
            handleAssetsBeans(bean);
            bean.setCheckStatus("盘亏");
        }
        for (String content : map.keySet()) {
            String name = map.get(content).get(0).getAssetName() + "等";
            mDataList.add(new ItemCheckData("事业部", content, "未知", name, String.valueOf(map.get(content).size())));
        }
        mAdapter.notifyDataSetChanged();
        mAdapter.setRequest(position -> {
            Map<String, List<OfflineCheckData.AssetsBean>> mapDept = new HashMap<>();
            for (OfflineCheckData.AssetsBean bean : map.get(mDataList.get(position).getContent())) {

            }
        });
        /*if (map.keySet().size() == 1) {
            String content = map.keySet().iterator().next();
            String name = map.get(content).get(0).getAssetName()+"等";
            dataList.add(new ItemCheckData("事业部", content, "位置", name, String.valueOf(map.get(content).size())));
        } else {}*/
    }

    private void handleAssetsBeans(OfflineCheckData.AssetsBean bean) {
        String division = bean.getDivision();
        if (map.containsKey(division)) {
            map.get(division).add(bean);
        } else {
            List<OfflineCheckData.AssetsBean> beanList = new ArrayList<>();
            beanList.add(bean);
            map.put(division, beanList);
        }
    }


}
